// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "EnhancedActionKeyMapping.h"
#include "GameSettingValue.h"
#include "UserSettings/EnhancedInputUserSettings.h"

#include "LyraSettingKeyboardInput.generated.h"

class UObject;

//--------------------------------------
// ULyraSettingKeyboardInput
//--------------------------------------

/**
 * 键盘输入设置类，继承自UGameSettingValue
 */
UCLASS()
class ULyraSettingKeyboardInput : public UGameSettingValue
{
	GENERATED_BODY()

public:
	ULyraSettingKeyboardInput();

	/**
	 * 初始化输入数据
	 */
	void InitializeInputData(const UEnhancedPlayerMappableKeyProfile* KeyProfile, const FKeyMappingRow& MappingData, const FPlayerMappableKeyQueryOptions& QueryOptions);

	/**
	 * 根据插槽获取键位文本
	 */
	FText GetKeyTextFromSlot(const EPlayerMappableKeySlot InSlot) const;
	
	/**
	 * 存储初始设置
	 */
	virtual void StoreInitial() override;
	/**
	 * 重置为默认值
	 */
	virtual void ResetToDefault() override;
	/**
	 * 恢复到初始值
	 */
	virtual void RestoreToInitial() override;

	/**
	 * 更改绑定
	 */
	bool ChangeBinding(int32 InKeyBindSlot, FKey NewKey);
	/**
	 * 获取键位映射的所有动作
	 */
	void GetAllMappedActionsFromKey(int32 InKeyBindSlot, FKey Key, TArray<FName>& OutActionNames) const;

	/** 返回此设置的映射是否已自定义 */
	bool IsMappingCustomized() const;
	
	/**
	 * 获取设置显示名称
	 */
	FText GetSettingDisplayName() const;
	/**
	 * 获取设置显示分类
	 */
	FText GetSettingDisplayCategory() const;

	/**
	 * 查找键位映射行
	 */
	const FKeyMappingRow* FindKeyMappingRow() const;
	/**
	 * 查找可映射键位配置文件
	 */
	UEnhancedPlayerMappableKeyProfile* FindMappableKeyProfile() const;
	/**
	 * 获取用户设置
	 */
	UEnhancedInputUserSettings* GetUserSettings() const;
	
protected:
	/** ULyraSetting */
	/**
	 * 初始化时调用
	 */
	virtual void OnInitialized() override;

protected:

	/** 此动作映射的名称 */
	FName ActionMappingName; // 动作映射名称

	/** 查询选项，用于过滤此设置的键位 */
	FPlayerMappableKeyQueryOptions QueryOptions; // 查询选项

	/** 此键位设置来自的配置文件标识符 */
	FString ProfileIdentifier; // 配置文件标识符

	/** 存储每个插槽的初始键位映射 */
	TMap<EPlayerMappableKeySlot, FKey> InitialKeyMappings; // 初始键位映射
};